blob: cf493be1ba529dd93e69ea8359741b2b1cc2722f [file] [log] [blame]
Harald Alvestrand168935a2015-05-13 08:23:141<!doctype html>
2<!--
Harald Alvestrand698efbc2015-05-18 08:53:053This test uses data only, and thus does not require fake media devices.
Harald Alvestrand168935a2015-05-13 08:23:144-->
5
6<html>
7<head>
8 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Harald Alvestrand698efbc2015-05-18 08:53:059 <title>RTCPeerConnection Data-Only Connection Test with Promises</title>
Harald Alvestrand168935a2015-05-13 08:23:1410</head>
11<body>
12 <div id="log"></div>
13 <h2>iceConnectionState info</h2>
14 <div id="stateinfo">
15 </div>
16
17 <!-- These files are in place when executing on W3C. -->
18 <script src="/resources/testharness.js"></script>
19 <script src="/resources/testharnessreport.js"></script>
20 <script src="/common/vendor-prefix.js"
21 data-prefixed-objects=
22 '[{"ancestors":["window"], "name":"RTCPeerConnection"},
23 {"ancestors":["window"], "name":"RTCSessionDescription"},
24 {"ancestors":["window"], "name":"RTCIceCandidate"}]'
25 >
26 </script>
27 <script type="text/javascript">
Harald Alvestrandba63db82015-05-19 08:33:4028 var test = async_test('Can set up a basic WebRTC call with only data using promises.');
Harald Alvestrand168935a2015-05-13 08:23:1429
30 var gFirstConnection = null;
31 var gSecondConnection = null;
32
Harald Alvestrand168935a2015-05-13 08:23:1433 var onIceCandidateToFirst = test.step_func(function(event) {
34 // If event.candidate is null = no more candidates.
35 if (event.candidate) {
36 var candidate = new RTCIceCandidate(event.candidate);
37 gSecondConnection.addIceCandidate(candidate);
38 }
39 });
40
41 var onIceCandidateToSecond = test.step_func(function(event) {
42 if (event.candidate) {
43 var candidate = new RTCIceCandidate(event.candidate);
44 gFirstConnection.addIceCandidate(candidate);
45 }
46 });
47
48 var onRemoteStream = test.step_func(function(event) {
49 assert_unreached('WebRTC received a stream when there was none');
50 });
51
52 var onIceConnectionStateChange = test.step_func(function(event) {
53 assert_equals(event.type, 'iceconnectionstatechange');
54 var stateinfo = document.getElementById('stateinfo');
55 stateinfo.innerHTML = 'First: ' + gFirstConnection.iceConnectionState
56 + '<br>Second: ' + gSecondConnection.iceConnectionState;
57 // Note: All these combinations are legal states indicating that the
58 // call has connected. All browsers should end up in completed/completed,
59 // but as of this moment, we've chosen to terminate the test early.
60 // TODO: Revise test to ensure completed/completed is reached.
61 if (gFirstConnection.iceConnectionState == 'connected' &&
62 gSecondConnection.iceConnectionState == 'connected') {
63 test.done()
64 }
65 if (gFirstConnection.iceConnectionState == 'connected' &&
66 gSecondConnection.iceConnectionState == 'completed') {
67 test.done()
68 }
69 if (gFirstConnection.iceConnectionState == 'completed' &&
70 gSecondConnection.iceConnectionState == 'connected') {
71 test.done()
72 }
73 if (gFirstConnection.iceConnectionState == 'completed' &&
74 gSecondConnection.iceConnectionState == 'completed') {
75 test.done()
76 }
77 });
78
Harald Alvestrand168935a2015-05-13 08:23:1479 // This function starts the test.
80 test.step(function() {
81 gFirstConnection = new RTCPeerConnection(null);
82 gFirstConnection.onicecandidate = onIceCandidateToFirst;
83 gFirstConnection.oniceconnectionstatechange = onIceConnectionStateChange;
84
85 gSecondConnection = new RTCPeerConnection(null);
86 gSecondConnection.onicecandidate = onIceCandidateToSecond;
87 gSecondConnection.onaddstream = onRemoteStream;
88 gSecondConnection.oniceconnectionstatechange = onIceConnectionStateChange;
89
Harald Alvestrand698efbc2015-05-18 08:53:0590 // The createDataChannel is necessary and sufficient to make
91 // sure the ICE connection be attempted.
92 gFirstConnection.createDataChannel('channel');
Harald Alvestrand4ec420d2015-05-18 14:31:5293
Harald Alvestrand1a596652015-05-19 08:45:3294 var atStep = 'Create offer';
Harald Alvestrand698efbc2015-05-18 08:53:0595
96 gFirstConnection.createOffer()
97 .then(function(offer) {
Harald Alvestrandf7a85392015-05-20 08:05:1598 atStep = 'Set local description at first';
99 return gFirstConnection.setLocalDescription(offer);
100 })
101 .then(function() {
102 atStep = 'Set remote description at second';
103 return gSecondConnection.setRemoteDescription(
104 gFirstConnection.localDescription);
Harald Alvestrand698efbc2015-05-18 08:53:05105 })
106 .then(function() {
Harald Alvestrand1a596652015-05-19 08:45:32107 atStep = 'Create answer';
Harald Alvestrand698efbc2015-05-18 08:53:05108 return gSecondConnection.createAnswer()
109 })
110 .then(function(answer) {
Harald Alvestrandf7a85392015-05-20 08:05:15111 atStep = 'Set local description at second';
112 return gSecondConnection.setLocalDescription(answer);
Harald Alvestrand698efbc2015-05-18 08:53:05113 })
114 .then(function() {
Harald Alvestrandf7a85392015-05-20 08:05:15115 atStep = 'Set remote description at first';
116 return gFirstConnection.setRemoteDescription(
117 gSecondConnection.localDescription);
118 })
119 .then(function() {
120 atStep = 'Negotiation completed';
Harald Alvestrand698efbc2015-05-18 08:53:05121 })
122 .catch(test.step_func(function(e) {
Harald Alvestrandba63db82015-05-19 08:33:40123 assert_unreached('Error ' + e.name + ': ' + e.message +
Harald Alvestrand698efbc2015-05-18 08:53:05124 ' happened at step ' + atStep);
125 }));
Harald Alvestrand168935a2015-05-13 08:23:14126 });
127</script>
128
129</body>
130</html>